var http=require('http'),fs=require('fs'),path=require('path');

http.createServer(function (req, res) {
    var file=path.normalize('.'+req.url);

    console.log('file:',file);

    function sendErr(err){
        console.log('Err:',err);
        res.writeHead(500);
        res.end('Interval Server Error.');
    }

    fs.exists(file, function (ex) {
        var rs;
        if(ex){
            fs.stat(file, function (err,st) {
                if(err)return sendErr(err);

                if(st.isDirectory()){
                    res.writeHead(403);
                    res.end('Forbidden');
                }else{
                    rs=fs.createReadStream(file);
                    rs.on('error',sendErr);
                    res.writeHead(200);
                    rs.pipe(res);
                }
            });
        }else{
            res.writeHead(404);
            res.end('Not found.');
        }
    });

}).listen(3000,function(){
    console.log('Static 3000');
});